<?php

namespace App\Http\Controllers\Cruise\Archive;

use App\Http\Controllers\BaseController;
use App\Service\Cruise\Archive\ArchiveService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class ArchiveController extends BaseController
{

    public function franchiseeDetail(Request $request, $shopId)
    {
        return $this->success(ArchiveService::franchiseeDetail($shopId));
    }



    /**
     * 编辑加盟商档案
     * @param Request $request
     * @param $id
     * @return JsonResponse
     */
    public function franchiseeUpdate(Request $request, $id)
    {
        $this->validate($request, [
            'mobile'                => 'required',
            'remarkMobile1'         => '',
            'remarkMobile2'         => '',
            'isSelfManaged'         => 'required',
            'shopBudget'            => 'required',
            'investmentMode'        => 'required',
            'financeSource'         => 'required',
            'cateringExperience'    => 'required',
            'joinChainExperience'   => 'required',
            'employmentExperience'  => 'required',
            'workLife'              => 'required',
            'educationalBackground' => 'required',
            'occupationBackground'  => 'required',
        ]);
        ArchiveService::franchiseeUpdate($id, $request->all());
        return $this->success();
    }

    /**
     * 查询 门店档案-营业执照和许可证 详情
     * @param Request $request
     * @param $shopId
     * @return JsonResponse
     */
    public function shopArchiveDetail(Request $request, $shopId): JsonResponse
    {
        return $this->success(ArchiveService::shopArchiveDetail($shopId));
    }


    /**
     * 修改 门店档案-营业执照和许可证
     * @param Request $request
     * @param $shopId
     * @return JsonResponse
     * @throws ValidationException
     */
    public function shopArchiveUpdate(Request $request, $shopId): JsonResponse
    {
        $this->validate(
            $request, [
                'businessLicense'              => 'required|string|min:0',
                'businessLicenseUrl'           => 'required|string|min:0',
                'businessLicenseStartDate'     => 'required|date|min:0',
                'businessLicenseEndDate'       => 'required|date|min:0',
                'foodBusinessLicense'          => 'required|string|min:0',
                'foodBusinessLicenseUrl'       => 'required|string|min:0',
                'foodBusinessLicenseStartDate' => 'required|date|min:0',
                'foodBusinessLicenseEndDate'   => 'required|date|min:0',
            ]
        );
        ArchiveService::shopArchiveUpdate($shopId, $request->all());
        return $this->success();
    }
}
